package name.marz.to.go.ahg.saison.executer;

import java.io.File;
import java.net.URI;

import name.marz.to.go.ahg.common.util.HttpUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.executer.FileDownloadExecuter;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class SaisonCSVDownloader extends FileDownloadExecuter {

	public SaisonCSVDownloader(URI uri, AutoGetterHttpClient client, File file, Document dlDoc) {
		super(uri, client, file);
		setPageName("CSVダウンロード");
		Elements e = dlDoc.getElementsByAttributeValue("alt", "CSVダウンロード");
		if ( e.size() == 0 ) throw new IllegalStateException("CSVダウンロードのURLが見つかりません");
		Element a = e.first().parent();
		super.uri = HttpUtil.createURISafety(uri.getScheme(), uri.getAuthority()
						, a.attr("href")
					);
	}
}